﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Snom.Tests.Properties;
using System.Threading;

namespace Snom.Tests
{
    [TestClass]
    public class KeysTests
    {
        [TestMethod]
        public void ProxyWithCredentials()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress, Settings.Default.MyPhoneUsername, Settings.Default.MyPhonePassword, new Uri(Settings.Default.MyProxyUrl)))
            {
                snomPhone.SendKey(SnomKeys.Key0);
                snomPhone.SendKey(SnomKeys.Key1);
            }
        }

        [TestMethod]
        public void Proxy()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress, new Uri(Settings.Default.MyProxyUrl)))
            {
                snomPhone.SendKey(SnomKeys.Key0);
                snomPhone.SendKey(SnomKeys.Key1);
            }
        }

        [TestMethod]
        public void Mute()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress))
            {
                snomPhone.ExecuteCommandSequence("{Mute}");
                snomPhone.ToggleMute();
            }
        }

        [TestMethod]
        public void SimpleCall()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress))
            {
                snomPhone.ExecuteCommandSequence("144{Enter}");
            }
        }

        [TestMethod]
        public void KeysSequenceWithProxy()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress, new Uri("http://localhost:8888")))
            {
                snomPhone.SendKey(SnomKeys.Key0);
                snomPhone.SendKey(SnomKeys.Key0);
                snomPhone.SendKey(SnomKeys.Key0);
            }
        }

        [TestMethod]
        public void KeysSequenceWithOutProxy()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress))
            {
                snomPhone.SendKey(SnomKeys.Key0);
                snomPhone.SendKey(SnomKeys.Key0);
                snomPhone.SendKey(SnomKeys.Key0);
            }
        }

        [TestMethod]
        public void Dtmf()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress))
            {
                snomPhone.SendDtmfKey(SnomKeys.Dtmf0);
                snomPhone.SendDtmfKey(SnomKeys.Dtmf1);
                snomPhone.SendDtmfKey(SnomKeys.Dtmf2);
            }
        }

        [TestMethod]
        public void DtmfInCommandSequence()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress))
            {
                snomPhone.ExecuteCommandSequence("1234{Enter}{Wait 10}{Dtmf1}{Dtmf2}{Dtmf3}");
                snomPhone.ExecuteCommandSequence("1234{Enter}{Wait 10}{Dtmf 1234#}");
            }
        }

        [TestMethod]
        public void RawDtmfCommandSequence()
        {
            using (SnomPhone snomPhone = new SnomPhone(Settings.Default.MyPhoneIpAddress))
            {
                snomPhone.ExecuteCommandSequence("{Dial 555}{Wait 13}{Dtmf 2325874#}{Wait 4}{Cancel}");
                //snomPhone.ExecutePhoneRequest(string.Format("http://{0}/command.htm?ivr=555;2325874%23", Settings.Default.MyPhoneIpAddress));
                //snomPhone.ExecutePhoneRequest(string.Format("http://{0}/command.htm?number=555;2325874%23", Settings.Default.MyPhoneIpAddress));
                
                //snomPhone.ExecutePhoneRequest(string.Format("http://{0}/command.htm?key_dtmf=2325874", Settings.Default.MyPhoneIpAddress));
            }
        }

    }
}
